package com.huixue.server.rule;

import org.apache.ibatis.session.SqlSession;
import org.json.JSONException;
import org.json.JSONObject;

import com.huixue.server.basic.Common;
import com.huixue.server.interfaces.IRule;
import com.huixue.server.mapper.CustomerMapper;
import com.huixue.server.model.Customer;

/*!
 * 接口1115
 * 
 * 用于创建合同
 * 
 * 请求：{}
 * 响应：
 * 	[正确]{"code":"200","message":"新增成功"}
 * 	[错误]{"code":"201","message":"新增失败"}
 * 
 * @author look
 *
 */
public class Rule1115 implements IRule {

	public String doIt(SqlSession session, String requestData) {
		CustomerMapper customerMapper = session.getMapper(CustomerMapper.class);
		Customer customer = new Customer();
		try {
			JSONObject jo = new JSONObject(requestData);
			customer.setContractNumber(jo.getString("contract_numer"));
			customer.setCustomerName(jo.getString("customer_name"));
			customer.setContractExpires(jo.getString("contract_expires"));
			customer.setContractLimit(jo.getString("contract_limit"));
			customer.setContractStatus(jo.getString("contract_status"));
			customer.setOnsetTime(jo.getString("onset_time"));
			customer.setCreateTime(Common.getSystemDate().toString());

			customerMapper.createCustomer(customer);
			return "{\"code\":\"200\",\"message\":\"新增成功\"}";
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return "{\"code\":\"201\",\"message\":\"新增失败\"}";
	}
}
